package com.mxx.pmxt.controller;

import com.mxx.pmxt.model.GoodsModel;
import com.mxx.pmxt.service.GoodsService;
import com.mxx.pmxt.service.PUserService;
import com.mxx.pmxt.service.UserGoodsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.math.BigDecimal;

/**
 * Created by 马潇霄 on 2017/4/25.
 */
@Controller
public class PuserGoodsController
{
    @Resource
    UserGoodsService userGoodsService;

    @Resource
    GoodsService goodsService;

    @Resource
    PUserService userService;

    @RequestMapping("putMoney")
    public String putMoney(int gid, HttpSession session, BigDecimal newprice, Model model){
        int i = userGoodsService.putMoney(gid,(String)session.getAttribute("uname"),newprice);
        if (i==1){
            session.setAttribute("account",userService.getUserAccount((String)session.getAttribute("uname")));
        }
        GoodsModel goodsModel = goodsService.selectGoodModelByGid(gid);
        model.addAttribute("goods",goodsModel);
        BigDecimal nowPrice = userGoodsService.maxPriceByGid(gid);
        model.addAttribute("nowprice",nowPrice);
        model.addAttribute("state",i);
        return "goodsdetail";
    }
}
